<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@page import="com.cb.domain.service.bbase.CategoryManager"%>
<%@page import="com.cb.core.util.AppUtil"%>
<%@page import="java.util.List"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="StyleSheet" href="${ctxPath}/css/dtree.css" type="text/css" />
<script type="text/javascript" src="${ctxPath}/resource/common/js/dtree.js"></script>
<title>Insert title here</title>
</head>

<body>
	<%
		CategoryManager categoryManager=(CategoryManager)AppUtil.getById("categoryManager");
		List list=categoryManager.getByParentId(null);
		request.setAttribute("categoryList",list);
	%>
	<div class="dtree">

	<p><a href="javascript: d.openAll();">open all</a> | <a href="javascript: d.closeAll();">close all</a></p>
	
	<script type="text/javascript">
		
		d = new dTree('d');
		d.add(0,-1,'category');
		function addNode(pid,parentId,name,url){
			d.add(pid,parentId,name,url);
			}
	</script>

	<c:forEach items="${categoryList}" var="category">
		<script type="text/javascript">
			addNode(${category.categoryId},0,"${category.categoryName}","productSearch.do?categoryId=${category.categoryId}");
		</script>
		<c:if test="${not empty category.subComposites}">
			<c:forEach items="${category.subComposites}" var="secondCate">
					<script type="text/javascript">
						addNode(${secondCate.categoryId},${secondCate.parentId},"${secondCate.categoryName}","productSearch.do?categoryId=${secondCate.categoryId}");
					</script>
					<c:if test="${not empty secondCate.subComposites}">
						<c:forEach items="${secondCate.subComposites}" var="thirdCate">
							<script type="text/javascript">
								addNode(${thirdCate.categoryId},${thirdCate.parentId},"${thirdCate.categoryName}","productSearch.do?categoryId=${thirdCate.categoryId}");
							</script>
								<c:if test="${not empty thirdCate.subComposites}">	
										<c:forEach items="${thirdCate.subComposites}" var="fourthCate">
										<script type="text/javascript">
											addNode(${fourthCate.categoryId},${fourthCate.parentId},"${fourthCate.categoryName}","productSearch.do?categoryId=${fourthCate.categoryId}");
										</script>
										</c:forEach>
								</c:if>
						</c:forEach>
					</c:if>
			</c:forEach>
	
		</c:if>
	</c:forEach>
	<script type="text/javascript">
		document.write(d);
	</script>
</div>
</body>
</html>